package org.bw.controller;


import org.bw.entity.Type;
import org.bw.service.ITypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import javax.annotation.PostConstruct;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author hy.wu
 * @since 2022-07-12
 */
@RestController
@RequestMapping("/type")
public class TypeController {
    @Autowired
    ITypeService typeService;
    @Autowired
    RedisTemplate redisTemplate;

    @PostConstruct
    public void init(){
        List<Type> typeList = typeService.list();
        if (redisTemplate.hasKey("typeList")){
            redisTemplate.delete("typeList");
        }
        redisTemplate.opsForList().leftPushAll("typeList",typeList);
    }
    @RequestMapping("/typeList")
    public List<Type> typeList(){
        return redisTemplate.opsForList().range("typeList",0,-1);
    }

}
